<?php
class badword extends command {

	public function __construct(){
		$this->name = 'badword';
		$this->public = false;
		$this->channels = array('#juchipila');
		$this->server = 'irc.juchipila.com';
	}

	public function help(){
		return "Uso: !badword <palabra a agregar> . Agrega una nueva palabra a la lista negra.";
	}	
	
	public function process($args){
		if ( ! $this->issuedbyadmin){
			return 0;
		}
		$this->output = "";
		global $db;
		$badword = strtolower(trim($args));
		
		$sql = "select count(1) as count from badwords where word = :word";
		$r = $db->Parse($sql);
		$r->Bind(":word", $badword);
		$r->Execute();
		$row = $r->GetRow();
		if ( $row->count > 0){	
			$this->output = "La palabra < {$badword} > ya existia en la lista negra.";
		} else {
		
			$sql = "insert into badwords (word) values (:word)";
			$r = $db->Parse($sql, 1);
			$r->Bind(":word", $badword);
			$r->Execute();
			if ( $r->RowCount()){
				$this->output = "Palabra < {$badword} > agregada a la lista negra";
				global $badwords;
				$badwords[] = $badword;
			} else {
				$this->output = "No se pudo agregar la palabra < {$badword} > a la lista negra.";
			}
		}		
	}
}
?>